OB.Wms_ActionButton = OB.Wms_ActionButton || {};

//领料申请明细值变更时触发方法
OB.Wms_ActionButton.PutMaterialHzChange = function (item, view, form, grid) {
	var viewGrid = view.parentView.viewGrid;
	var head = viewGrid.getSelectedRecord();
	
	OB.Wms_ActionButton.getStorageProductInfo(form, 
		form.getValue("product"), head.warehouse, form.getValue("emesVendor"), 
		form.getValue("locator"), form.getValue("wmsQualityGrade"), form.getValue("batchNo"));
	return true;
};

//退货明细明细，值变更触发
OB.Wms_ActionButton.ReturnGoodsDetailChange = function (item, view, form, grid) {
	var viewGrid = view.parentView.viewGrid;
	var head = viewGrid.getSelectedRecord();
	
	OB.Wms_ActionButton.getStorageProductInfo(form, 
		form.getValue("product"), head.warehouse, head.emesVendor, 
		form.getValue("locator"), form.getValue("wmsQualityGrade"), form.getValue("batchNo"));
	return true;
};

//销售退货明细，物料变更触发
OB.Wms_ActionButton.WmsSalesReturnMxProductChange = function (item, view, form, grid) {
	var viewGrid = view.parentView.viewGrid;
	var head = viewGrid.getSelectedRecord();
	console.log("congxinazhi:", item, view, form, grid, head);
	OB.RemoteCallManager.call("com.wms.handler.change.WmsSalesReturnMxHandler",{
		productId: item._value, returnId: head.id},{},
			function(rpcResponse,data,rpcRequest) {
				console.log(data);
				form.setItemValue('qtyIn', data.qtyin);
			}
		);
};

//值变更后调用方法
OB.Wms_ActionButton.getStorageProductInfo = function(form, productId, warehouseId, vendorId, locatorId, qgId, batchNo) {
	OB.RemoteCallManager.call("com.wms.handler.change.ValueChangeGetProductInfoHandler",{
		productId: productId, warehouseId: warehouseId, vendorId: vendorId, locatorId: locatorId, 
		qualityGradeId: qgId, batchNo: batchNo
	},{}, function(rpcResponse,data,rpcRequest) {
			form.setItemValue('storageQty', data.storageQty);
			form.setItemValue('product$name', data.product);
			try {
				if (form.getItemValue('uom') == "") {
					form.setItemValue('uom', data.uomId);
				}
			} catch (e) {}
			try {
				if (form.getItemValue('emesVendor') == "") {
					form.setItemValue('emesVendor', data.vendorId);
					form.setItemValue('emesVendor$name', data.vendor);
				}
			} catch (e) {}
		}
	);
}

//库存批次信息冻结
OB.Wms_ActionButton.Frozen_Check_Button  = function(params, view) { 
	var views = view.activeView.viewGrid;
	var records = views.getSelectedRecords();
	var length = records.getLength();
	if (length) {
		isc.confirm("确定冻结？", function(ok) {
			if (ok) {
				// 选择纪录行
				var selectRecords = [];
				for ( var i = 0; i < length; i++) {
					selectRecords.push(records[i].batchNo);
				}
				OB.RemoteCallManager.call("com.wms.handler.change.FrozenStockHandler", {
						ids : selectRecords.join("#####")
					}, {}, function(request, data, response) {
						if (data.flag) {
							views.refreshGrid();
							isc.showMessage(data.message);
						} else {
							isc.showMessage(data.message);
						}
					}
				);
			}
		});
	} else {
		isc.showMessage("请选择纪录！");
	}
};